
@{
    ViewData["Title"] = "调拨单";
}

<style type="text/css">
    form {
        margin: 0;
    }

    textarea {
        display: block;
        width: 316px;
        margin-left: 702px;
    }

    .need {
        FONT-STYLE: normal;
        FONT-FAMILY: 微软雅黑;
        FONT-SIZE: 13px;
        TEXT-DECORATION: none;
        width: 75px;
    }

    .yincang {
        display: none;
    }

    .auto-style21 {
        width: 100px;
    }

    #totalAccunt {
        width: 79px;
    }
</style>
<script src="~/js/LodopFuncs_new.js"></script>
 
<object id="LODOP" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width="0" height="0" style="display: none;">
    <embed id="LODOP_EM" type="application/x-print-lodop" width="0" height="0"></embed>
</object>

<form id="mainForm" name="mainForm" method="post" runat="server">
    <div class="mini-toolbar" style="border-bottom: 0; padding: 0px; padding-left: 10px;">
        <table style="width: 100%">
            <tr>
                <td>
                    <label class="need">调拨单号：</label>
                    <input id="who_code" name="who_code" class="mini-textbox" value="@Model.data.who_code" enabled="false" />
                    <input id="who_id" name="who_id" class="mini-hidden" value="@Model.data.who_id" />
                    <input id="update_time" name="update_time" class="mini-hidden" value="@Model.data.update_time" />
                </td>
                <td>
                    <label class="need">调拨状态：</label>
                    <input class="mini-combobox" id="who_status" name="who_status" textField="name" valueField="id" data="[{id:'0',name:'保存'},{id:'1',name:'调出途中-提交'},{id:'2',name:'调入确认'},{id:'3',name:'核准'}]" showNullItem="true" nullitemtext="请选择..." value="@Model.data.who_status" enabled="false" />
                </td>

                <td>
                    <label class="need">调出时间：</label>
                    <input id="who_out_time" name="who_out_time" class="mini-datepicker" value="@Model.data.who_out_time" enabled="false" />
                </td>
                <td>
                    <a class="mini-button" id="doSave" style="width: 120px;" iconcls="icon-save" onclick="doSave()" enabled="false">保存</a>
                    <a class="mini-button" id="BringOut" style="width: 120px;" iconcls="icon-ok" onclick="BringOut()" enabled="false">调出确认</a>
                    <a class="mini-button" id="BringIn" style="width: 120px;" iconcls="icon-ok" onclick="BringIn()" enabled="false">调入确认</a>
                    @if (Html.CheckPermission("Wh.Order.Approve")){

                        <a class="mini-button" id="Approve" style="width: 120px;" iconcls="icon-ok" onclick="Approve()" enabled="false">核准</a>
                    }

                    <a class="mini-button" id="Print" style="width: 120px;" iconcls="icon-print" onclick="PrintDetail()">打印</a>
                </td>
            </tr>
            <tr>
                <td>
                    <label class="need">调出仓库：</label>
                    <input id="wh_id_out" name="wh_id_out" class="mini-combobox" textfield="wh_name" valuefield="wh_id" url="/wh/Order/GetWarehouseByUserOut" value="@Model.data.wh_id_out" required="true" enabled="false" />
                </td>
                <td>
                    <label class="need">调入仓库：</label>
                    @*<input id="wh_id_in" name="wh_id_in" class="mini-combobox" textfield="wh_name" valuefield="wh_id" shownullitem="true" valueFromSelect="true" url="/wh/Order/GetWarehouseByUserIn" value="@Model.data.wh_id_in" enabled="false" />*@
                    <input id="wh_id_in" name="wh_id_in" class="mini-buttonedit" onbuttonclick="onButtonEdit" allowInput="false" required="true" value="@Model.data.wh_id_in" text="@Model.data.wh_name_in" enabled="false" />
                </td>

                <td>
                    <label class="need">调入时间：</label>
                    <input id="who_in_time" name="who_in_time" class="mini-datepicker" value="@Model.data.who_in_time" enabled="false" />
                </td>
                <td>
                    <a class="mini-button" id="Delete" style="width: 120px;" iconcls="icon-remove" onclick="Delete()" enabled="false">删除</a>
                    <a class="mini-button" id="BringOutCancle" style="width: 120px;" iconcls="icon-no" onclick="BringOutCancle()" enabled="false">取消调出</a>
                    <a class="mini-button" id="BringInCancle" style="width: 120px;" iconcls="icon-no" onclick="BringInCancle()" enabled="false">取消调入</a>
                    @if (Html.CheckPermission("Wh.Order.ApproveCancle"))
                    {
                        <a class="mini-button" id="ApproveCancle" style="width: 120px;" iconcls="icon-no" onclick="ApproveCancle()" enabled="false">取消核准</a>
                    }
                </td>
            </tr>
        </table>
    </div>
</form>

<div style="width: 100%;">
    <div id="p1" class="mini-panel" title="调出条码" style="width:500px;height:200px;margin-top: 10px;display: inline-block;">
        <input id="areaOut" name="areaOut" class="mini-textarea" style="width: 100%;height: 100%;" value="@Model.data.product_barcodes_out" onvaluechanged="valuechanged" />
    </div>
    <div id="p2" class="mini-panel" title="调入条码" style="width:500px;height:200px;margin-top: 10px;display: inline-block;margin-left: 20px;">
        <input id="areaIn" name="areaIn" class="mini-textarea" style="width: 100%;height: 100%;" enabled="false" value="@Model.data.product_barcodes_in" />
    </div>
</div>

<div style="width: 100%">
    <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
        <table style="width: 100%;">
            <tr>
                <td>
                    <a class="mini-button" iconcls="icon-add" onclick="addBattery()" plain="true" id="bt1" enabled="false" >新增电池</a>
                    <a class="mini-button" iconcls="icon-remove" onclick="DeleteBattery()" plain="true" id="bt2" enabled="false" >删除电池</a>
                </td>
            </tr>
        </table>
    </div>
</div>

<div class="mini-fit">
    <div id="datagrid1"  showpager="false" class="mini-datagrid" allowCellEdit="true" allowCellSelect="true" style="width:100%;height:100%;" sortmode="client" idField="itemId" allowResize="true" oncellbeginedit="cellbeginedit" oncellendedit="cellendedit">
        <div property="columns">
            <div type="checkcolumn" width="40"></div>
            <div field="product_code" width="120" headerAlign="center" align="center">
                车型编码
            </div>
            <div field="product_prefixname" width="120" headerAlign="center" align="center">
                车型名称
            </div>
            <div field="whod_amount_product_out" width="120" headerAlign="center" align="center">
                调出数量
            </div>
            <div field="whod_amount_product_in" width="120" headerAlign="center" align="center">
                调入数量
            </div>
            <div field="battery_code" width="120" headerAlign="center" align="center">
                电池编码
            </div>
            <div autoShowPopup="true" field="battery_name" width="120" headerAlign="center" align="center" cellstyle="background-color:#66FFCC;">
                电池名称
                <input property="editor" id="btyName" class="mini-combobox" style="width:100%;" textField="battery_name" valueField="battery_code" />
            </div>
            <div field="whod_amount_battery_out" width="120" headerAlign="center" align="center" cellstyle="background-color:#66FFCC;" >
                调出数量(组)
                <input property="editor" class="mini-spinner" style="width:100%;" maxValue="9999" />
            </div>
            <div field="whod_amount_battery_in" width="120" headerAlign="center" align="center">
                调入数量(组)
                @*<input property="editor" class="mini-spinner" style="width:100%;" />*@
            </div>
        </div>
    </div>
</div>

<div id="choseWin" class="mini-window" title="新增电池" style="width: 640px; height: 400px;"
     showmaxbutton="true" showtoolbar="true" showfooter="true" showmodal="false" allowresize="true" allowdrag="true">
    <div class="mini-toolbar">
        <table style="padding: 10px;" id="divSearch">
            <tr>
                <td class="noneed"><b>电池编码：</b></td>
                <td>
                    <input class="mini-hidden" id="battery_wh_id" name="battery_wh_id" />
                    <input class="mini-textbox" id="battery_code" name="battery_code" />
                </td>
                <td class="noneed"><b>电池名称：</b></td>
                <td>
                    <input class="mini-textbox" id="battery_name" name="battery_name" />
                </td>
                <td class="noneed"><b>电池规格：</b></td>
                <td>
                    <input class="mini-textbox" id="battery_spec" name="battery_spec" />
                </td>
            </tr>
            <tr>
                <td colspan="3"></td>
                <td colspan="3">
                    <input class="mini-button" text="查询" iconcls="icon-search" onclick="SearchBty()" style="width: 100px;margin-left: 110px;" />
                    <input class="mini-button" text="选入" iconcls="icon-ok" onclick="doInsert()" style="width: 100px" />
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit">
        <div id="btygrid" class="mini-datagrid" style="width: 100%; height: 100%;"
             idfield="itemCode" sizelist="[20,50,100]" pagesize="20" allowalternating="true" sortmode="client" url="/wh/Order/getbatterylist" onrowdblclick="rowdblclick">
            <div property="columns">
                <div type="indexcolumn" width="20"></div>
                <div type="checkcolumn" width="20"></div>
                <div field="battery_code" align="center" width="120" headeralign="center" allowsort="true">电池名称</div>
                <div field="battery_name" align="center" width="120" headeralign="center" allowsort="true">电池编码</div>
                <div field="battery_spec" align="center" width="120" headeralign="center" allowsort="true">电池规格</div>
            </div>
        </div>
    </div>
</div>

<div id="win" class="mini-window" title="选择" style="width:630px;height:450px;"
     showMaxButton="true" showToolbar="true" showFooter="true" showModal="false" allowResize="true" allowDrag="true">
    <div property="toolbar" style="padding:5px;" id="divSearch2">
        <table>
            <tr>
                <td><label for="name">仓库名称:</label></td>
                <td><input class="mini-textbox" id="wh_name" name="wh_name" /></td>
                <td><label for="name">组织名称:</label></td>
                <td><input class="mini-textbox" id="org_name" name="org_name" /></td>
                <td> <a plain="true" class="mini-button" iconcls="icon-search" onclick="doSearch">查找</a></td>
                <td> <a plain="true" class="mini-button" iconcls="icon-ok" onclick="Insert">选入</a></td>
            </tr>
        </table>
    </div>
    <div class="mini-fit">
        <div id="datagrid2" class="mini-datagrid" url="/wh/Order/GetWarehouseByUserIn"
             allowResize="true" pageSize="20" multiSelect="true" idField="wh_id" style="width:100%;height:100%;" onrowdblclick="onRowdblClick">
            <div property="columns">
                <div type="indexcolumn" width="10"></div>
                <div field="wh_name" width="60" headerAlign="center" align="center">仓库名称</div>
                <div field="org_name" width="60" headerAlign="center" align="center">组织名称</div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    mini.parse();
    var p1 = mini.get("p1");
    var p2 = mini.get("p2");
    var btyGrid = mini.get("btygrid");
    var grid = mini.get("datagrid1");
    var oldCodes = mini.get("areaOut").getValue();
    document.getElementById("areaOut").oncontextmenu = function () {
        return false;
    }
    document.getElementById("areaOut").onkeydown = function () {
        if (event.ctrlKey && window.event.keyCode == 67) {
            return false;
        }
    }
    document.getElementById("areaOut").oncopy = function () {
        return false;
    }
    document.getElementById("areaOut").oncut = function () {
        return false;
    }

    $(function () {
        var who_id = mini.get("who_id").getValue();
        if (parseInt(who_id) !== 0) {
            GetDetail(who_id);
            if (@Model.data.who_status == 0) {
                mini.get("BringOut").enable();
                mini.get("Delete").enable();
                mini.get("bt1").enable();
                mini.get("bt2").enable();
                p1.setButtons([{ html: '<button style="position:relative;top:-4px;" onclick="OutCount()">生成调出数量</button>' }]);
            }
            else if (@Model.data.who_status == 1) {
                mini.get("BringOutCancle").enable();
                mini.get("BringIn").enable();
                mini.get("Delete").disable();
                mini.get("doSave").disable();
                mini.get("areaOut").disable();
                mini.get("areaIn").enable();
                p2.setButtons([{ html: '<button style="position:relative;top:-4px;" onclick="InCount()">生成调入数量</button>' }]);
            }
            else if (@Model.data.who_status == 2) {
                mini.get("Delete").disable();
                mini.get("doSave").disable();
                mini.get("areaOut").disable();
                mini.get("BringInCancle").enable();
                if (mini.get("Approve")) { 
                    mini.get("Approve").enable();
                }
            }
              else if (@Model.data.who_status == 3) {
                mini.get("Delete").disable();
                mini.get("doSave").disable();
                mini.get("areaOut").disable();
                mini.get("Print").enable();
                if (mini.get("ApproveCancle")) {
                    mini.get("ApproveCancle").enable();
                }
            }
        }
        else {
            p1.setButtons([{ html: '<button style="position:relative;top:-4px;" onclick="OutCount()">生成调出数量</button>' }]);
            mini.get("wh_id_out").enable();
            mini.get("wh_id_in").enable();
            mini.get("bt1").enable();
            mini.get("bt2").enable();
            mini.get("Print").disable();
        }
    });


    function GetDetail(who_id) {
        $.ajax({
            type: "post",
            url: "/wh/Order/getdetails",
            data: { id: who_id },
            dataType: "json",
            success: function (data) {
                if (data.length > 0) {
                    grid.setData(data);
                }
                else {
                    sx.error(data.info);
                }
            }
        });
    }

    function onButtonEdit(e) { 
        mini.get("win").show();
    }

    function doSearch() { 
        var form = new mini.Form("#divSearch2");
        var data = form.getData();
        mini.get("datagrid2").load(data);
    }
    function Insert() { 
        var select = mini.get("datagrid2").getSelected();
        if (select) {
            mini.get("wh_id_in").setValue(select.wh_id);
            mini.get("wh_id_in").setText(select.wh_name);
            mini.get("win").hide();
        }
        else {
            sx.error("请选择仓库!");
        }
    }

    function onRowdblClick(e) { 
        Insert();
    }

    function doSave() {
        mini.get("who_out_time").setValue(new Date());
        mini.get("who_in_time").setValue(new Date());
        var form = new mini.Form("#mainForm");
        form.validate();
        if (form.isValid() == false) {
            sx.error("请核对调入调出仓库!");
            return;
        }
        var fData = form.getData();
        if (fData.wh_id_in == fData.wh_id_out) {
            sx.error("调入仓库与调出仓库不能相同!");
            return;
        }
        var isSure = true;
        var data = grid.getData();
        if (parseInt(fData.who_id) == 0) {
            fData.who_status = 0;
        }
        if (data.length == 0) { 
            sx.error("无数据需要保存!");
            return;
        }
        for (var i = 0; i < data.length; i++) {
            if ((data[i].whod_amount_battery_out == undefined || data[i].whod_amount_battery_out == 0) && data[i]._state !== "removed" && data[i].battery_code !== "" && data[i].battery_code !== null && data[i].battery_code !== undefined) {
                sx.error("请输入电池调出数量!");
                isSure = false;
                break;
            }
            if (data[i].product_code == null || data[i].product_code == "" ) {
                data[i].product_code = '';
                data[i].product_color = '';
                data[i].product_prefixname = '';
                data[i].whod_amount_product_in = 0;
                data[i].whod_amount_product_out = 0;
            }
            if (data[i].battery_code == "" || data[i].battery_code == null || data[i].battery_code == undefined) { 
                data[i].battery_code = '';
                data[i].battery_name = ''; 
                data[i].battery_spec = ''; 
                data[i].whod_amount_battery_in = 0;
                data[i].whod_amount_battery_out = 0;
            }
        }
        if (isSure) {
            fData.wh_name_in = mini.get("wh_id_in").getText();
            fData.wh_name_out = mini.get("wh_id_out").getText();
            fData.product_barcodes_out = mini.get("areaOut").getValue();
            fData.product_barcodes_in = mini.get("areaIn").getValue();
            $.ajax({
                type: "post",
                url: "/wh/Order/EditAjax",
                data: { main: JSON.stringify(fData), data: JSON.stringify(data) },
                dataType: "json",
                success: function (data) {
                    if (data.resultCode == sx.resultCode.ok) {
                        window.location.href = '/wh/Order/edit?id=' + data.info;
                    }
                    else {
                        sx.error(data.info);
                    }
                }
            });
        }
    }

    //判断条码是否重复
    function arrRepeat(arr) {
        var arrStr = JSON.stringify(arr), str;
        for (var i = 0; i < arr.length; i++) {
            if (arrStr.indexOf(arr[i]) != arrStr.lastIndexOf(arr[i])) {
                return true;
            }
        };
        return false;
    }

    function OutCount() {
        var codes = mini.get("areaOut").getValue();
        var wh_id = mini.get("wh_id_out").getValue();
        var wh_id_in = mini.get("wh_id_in").getValue();
        var arrStr = codes.split(/[\n\r]/g);
        if (arrRepeat(arrStr)) { 
            sx.error("调出条码存在重复！");
            return;
        }
        if (wh_id == 0 || wh_id_in == 0) { 
            sx.error("请先选入调出、调出仓库！");
            return;
        }
        if (codes == "") { sx.error("请先扫入条码！"); }
        else {
            var index = codes.indexOf("'");
            if (index > 0) {
                sx.error("条码不正确，请检查！");
                mini.get("areaOut").setValue(oldCodes);
                return;
            }
            $.ajax({
                type: "post",
                url: "/wh/Order/getbattery",
                data: { codes: codes, wh_id: wh_id },
                dataType: "json",
                success: function (data) {
                    if (data.resultCode == sx.resultCode.error) { 
                        sx.error(data.info);
                        mini.get("areaOut").setValue(oldCodes);
                        return;
                    }
                    var resultarr = [];
                    if (data.length > 0) {
                        var savedata = grid.getData();
                        if (savedata.length > 0) {
                            $.each(data, function (i, n) {
                                var ishave = false;
                                $.each(savedata, function (ii, nn) {
                                    if (n.product_code == nn.product_code) {
                                        ishave = true;
                                        if (nn.whod_amount_product_out !== n.whod_amount_product_out) {
                                            nn.whod_amount_product_out = n.whod_amount_product_out;
                                        }
                                        resultarr.push(nn);
                                    }
                                    if (nn.product_code == "" || nn.product_code == null || nn.product_code == undefined) {
                                        var ISHAVE = false;
                                        $.each(resultarr, function (iii, nnn) {
                                            if (nn.battery_code == nnn.battery_code && (nnn.product_code == "" || nnn.product_code == null || nnn.product_code == undefined)) {
                                                ISHAVE = true;
                                            }
                                        });
                                        if (!ISHAVE) { 
                                            resultarr.push(nn);
                                        }
                                    }
                                });
                                if (!ishave) {
                                    resultarr.push(n);
                                }
                                if (n.product_code == "" || n.product_code == null || n.product_code == undefined) { 
                                    var ISHAVE = false;
                                    $.each(resultarr, function (iii, nnn) {
                                        if (n.battery_code == nnn.battery_code) {
                                            ISHAVE = true;
                                        }
                                    });
                                    if (!ISHAVE) {
                                        resultarr.push(nn);
                                    }
                                }
                            });
                        }
                        else {
                            resultarr = data;
                        }
                        grid.setData(resultarr);
                        mini.get("doSave").enable();
                        mini.get("BringOut").disable();
                        oldCodes = codes;
                    }
                }
            });
        }
    }

    function InCount() {
        var codesIn = mini.get("areaIn").getValue();
        var codesOut = mini.get("areaOut").getValue();
        if (codesIn == "" || codesOut !== codesIn) {
            sx.error("调入条码与调出条码没有完全一致！请检查！可联系仓库管理员查询问题原因！");
            return;
        }
        else {

            var id = mini.get("who_id").getValue();
            $.ajax({
                type: "post",
                url: "/wh/Order/GetInCount",
                data: { id: id },
                dataType: "json",
                success: function (data) {
                    if (data.resultCode == sx.resultCode.ok) {
                        GetDetail(id);
                    }
                    else {
                        sx.error(data.info);
                    }
                }
            });
         }
    }

    function addBattery() {
        var win = mini.get("choseWin");
        mini.get("battery_wh_id").setValue(mini.get("wh_id_out").getValue());
        if (mini.get("wh_id_out").getValue() == 0) {
            sx.error("请先选择调出仓库！");
            return;
        }
        win.show();
    }

    function DeleteBattery() {
        var selected = grid.getSelected();
        if (!selected) {
            sx.error("请先选择电池！");
            return;
        }
        if (selected.product_code !== "" && selected.product_code !== null && selected.product_code !== undefined) {
            sx.error("无法删除整车！");
            return;
        }
        else {
            grid.removeRow(selected);
        }
        var data = grid.getData();
        if (data.length == 0) {
            mini.get("doSave").disable();
        }
        else {
            mini.get("doSave").enable();
            mini.get("BringOut").disable();
        }
    }

    function SearchBty() {
        var form = new mini.Form("#divSearch");
        var data = form.getData();
        btyGrid.load(data);
    }

    function cellbeginedit(e) {
        var record = e.record;
        var field = e.field;
        if (@Model.data.who_status !== 0) {
            e.cancel = true;
        }
        else {
            if ((record.product_code !== undefined && record.product_code !== null && record.product_code !== "") && field == "battery_name") {
                var id = mini.get("wh_id_out").getValue();
                mini.get("btyName").load("/wh/Order/getbtybypcode?code=" + record.product_code + "&wh_id=" + id);
            }
            else if (field == "battery_name") {
                e.cancel = true;
            }
            if (field == "whod_amount_battery_out" && record.battery_code == "") {
                sx.error("请先选择电池！");
                e.cancel = true;
            }
        }
    }

    function cellendedit(e) {
        var record = e.record;
        var field = e.field;
        if (field == "battery_name" && (record.product_code !== undefined && record.product_code !== null && record.product_code !== "")) {
            var text = mini.get("btyName").getText();
            if (text !== "") {
                record.battery_code = record.battery_name;
                record.battery_name = text;
                grid.updateRow(record);
            }
        }
        $.each(grid.getData(), function (i, n) {
            if (n._state == "modified") { 
                mini.get("doSave").enable();
                mini.get("BringOut").disable();
            }
        });
    }


    function doInsert() {
        var select = btyGrid.getSelected();
        if (select) {
            doCheck(select);
        }
        else {
            sx.error("请选择电池!");
        }
    }

    function rowdblclick(e) {
        var record = e.record;
        doCheck(record);
    }

    function doCheck(select) {
        var data = grid.getData();
        var isHave = false;
        $.each(data, function (i, n) {
            if ((data[i].product_code == "" || data[i].product_code == null || data[i].battery_code == undefined) && n.battery_code == select.battery_code) {
                isHave = true;
                data[i].whod_amount_battery_out = data[i].whod_amount_battery_out + 1;
                grid.updateRow(data[i]);
            }
        });
        if (!isHave) {
            select.whod_amount_battery_out = 1;
            grid.addRow(select);
            mini.get("doSave").enable();
            mini.get("BringOut").disable();
        }
    }

    function Delete() {
        var who_id = mini.get("who_id").getValue();
        $.ajax({
            type: "post",
            url: "/wh/Order/Delete",
            data: { id: who_id },
            dataType: "json",
            success: function (data) {
                if (data.resultCode == sx.resultCode.ok) {
                    window.location.href = '/wh/Order/edit';
                }
                else {
                    sx.error(data.info);
                }
            }
        });
    }

    function BringOut() {
        mini.get("who_out_time").setValue(new Date());
        var id = mini.get("who_id").getValue();
        $.ajax({
            type: "post",
            url: "/wh/Order/DoCheckBringOut",
            data: { id: id, update_time: mini.get("update_time").getValue(), wh_name_in: mini.get("wh_id_in").getText(), wh_name_out: mini.get("wh_id_out").getText() },
            dataType: "json",
            success: function (data) {
                if (data.resultCode == sx.resultCode.ok) {
                    window.location.href = '/wh/Order/edit?id=' + id;
                }
                else {
                    sx.error(data.info);
                }
            }
        });
    }

    function BringOutCancle() {
        var id = mini.get("who_id").getValue();
        $.ajax({
            type: "post",
            url: "/wh/Order/DoBringOutCancle",
            data: { id: id, update_time: mini.get("update_time").getValue(), wh_name_in: mini.get("wh_id_in").getText(), wh_name_out: mini.get("wh_id_out").getText() },
            dataType: "json",
            success: function (data) {
                if (data.resultCode == sx.resultCode.ok) {
                    window.location.href = '/wh/Order/edit?id=' + id;
                }
                else {
                    sx.error(data.info);
                }
            }
        });
    }

    function BringIn() {
        mini.get("who_in_time").setValue(new Date());
        var codesIn = mini.get("areaIn").getValue();
        var codesOut = mini.get("areaOut").getValue();
        if (codesIn == "" || codesOut !== codesIn) {
            sx.error("调入条码与调出条码没有完全一致！请检查！可联系仓库管理员查询问题原因！");
            return;
        }
        var data = grid.getData();
        var count = true;
        $.each(data, function (i, n) {
            if ((n.whod_amount_battery_in !== n.whod_amount_battery_out || n.whod_amount_product_in !== n.whod_amount_product_out) && n.product_code !== "" && n.battery_code !==  "") {
                count = false;
            }
        });
        if (!count) {
            sx.error("调入数量与调出数量须相等!");
            return;
        }
        var id = mini.get("who_id").getValue();
        $.ajax({
            type: "post",
            url: "/wh/Order/DoBringIn",
            data: { id: id, update_time: mini.get("update_time").getValue(), wh_name_in: mini.get("wh_id_in").getText(), wh_name_out: mini.get("wh_id_out").getText() },
            dataType: "json",
            success: function (data) {
                if (data.resultCode == sx.resultCode.ok) {
                    window.location.href = '/wh/Order/edit?id=' + id;
                }
                else {
                    sx.error(data.info);
                }
            }
        });
    }

    function BringInCancle() {
        var id = mini.get("who_id").getValue();
        $.ajax({
            type: "post",
            url: "/wh/Order/BringInCancle",
            data: { id: id, update_time: mini.get("update_time").getValue(), wh_name_in: mini.get("wh_id_in").getText(), wh_name_out: mini.get("wh_id_out").getText() },
            dataType: "json",
            success: function (data) {
                if (data.resultCode == sx.resultCode.ok) {
                    window.location.href = '/wh/Order/edit?id=' + id;
                }
                else {
                    sx.error(data.info);
                }
            }
        });
    }

    function Approve() {
        var id = mini.get("who_id").getValue();
        $.ajax({
            type: "post",
            url: "/wh/Order/Approve",
            data: { id: id, update_time: mini.get("update_time").getValue()},
            dataType: "json",
            success: function (data) {
                if (data.resultCode == sx.resultCode.ok) {
                    window.location.href = '/wh/Order/edit?id=' + id;
                }
                else {
                    sx.error(data.info);
                }
            }
        });
    }

    function ApproveCancle() {
        var id = mini.get("who_id").getValue();
        $.ajax({
            type: "post",
            url: "/wh/Order/ApproveCancle",
            data: { id: id, update_time: mini.get("update_time").getValue() },
            dataType: "json",
            success: function (data) {
                if (data.resultCode == sx.resultCode.ok) {
                    window.location.href = '/wh/Order/edit?id=' + id;
                }
                else {
                    sx.error(data.info);
                }
            }
        });
    }

    function valuechanged(e) { 
        mini.get("doSave").disable();
    }

    function PrintDetail() {
        var who_in_time = mini.get("who_in_time").getText();
        var who_out_time = mini.get("who_out_time").getText();
        var wh_name_in = mini.get("wh_id_in").getText();
        var wh_name_out = mini.get("wh_id_out").getText();
        var who_status = mini.get("who_status").getText();
        var who_code = mini.get("who_code").getValue();


        //Search();

        var data = mini.get("datagrid1").getData();
        var result = [];
        if (data.length == 0) {
            sx.error("无数据需要打印！");
            return;
        }
        else {
            var num = 1;
            $.each(data, function (i, n) {
                if (n.product_code !== "" && n.product_code !== null) {
                    result.unshift({ row: num, code: n.product_code, detail: n.product_prefixname + "/" + n.product_color, out_num: n.whod_amount_product_out, in_num: n.whod_amount_product_in });
                    num++;
                }
                if (n.battery_code !== "" && n.battery_code !== null) {
                    result.push({ row: num, code: n.battery_code, detail: n.battery_name + "/" + n.battery_spec, out_num: n.whod_amount_battery_out, in_num: n.whod_amount_battery_in });
                    num++;
                }
            });

        }

        LODOP = getLodop(document.getElementById('LODOP'), document.getElementById('LODOP_EM'));
        //LODOP.SET_LICENSES("浙江绿源电动车有限公司", "853627763666789907689190562356", "", "");
        LODOP.PRINT_INIT("调拨单(" + who_status + ")");

        var i = 0;
        var fontsize = 0;
        var date = new Date();

        fontsize++;
        LODOP.ADD_PRINT_TEXTA(i.toString() + fontsize, 25, 320, 700, 20, "调拨单(" + who_status + ")");
        LODOP.SET_PRINT_STYLEA(i.toString() + fontsize, "FontSize", 14);
        LODOP.SET_PRINT_STYLEA(i.toString() + fontsize, "Bold", 1);

        fontsize++;
        LODOP.ADD_PRINT_TEXTA(i.toString() + fontsize, 50, "6%", 700, 20, "调拨单号：" + who_code);
        LODOP.SET_PRINT_STYLEA(i.toString() + fontsize, "FontSize", 12);
        LODOP.SET_PRINT_STYLEA(i.toString() + fontsize, "Bold", 1);

        fontsize++;
        LODOP.ADD_PRINT_TEXTA(i.toString() + fontsize, 50, "36%", 700, 20, "调出仓库：" + wh_name_out);
        LODOP.SET_PRINT_STYLEA(i.toString() + fontsize, "FontSize", 12);
        LODOP.SET_PRINT_STYLEA(i.toString() + fontsize, "Bold", 1);

        fontsize++;
        LODOP.ADD_PRINT_TEXTA(i.toString() + fontsize, 50, "66%", 700, 20, "调入仓库：" + wh_name_in);
        LODOP.SET_PRINT_STYLEA(i.toString() + fontsize, "FontSize", 12);
        LODOP.SET_PRINT_STYLEA(i.toString() + fontsize, "Bold", 1);

        fontsize++;
        LODOP.ADD_PRINT_TEXTA(i.toString() + fontsize, 70, "6%", 700, 20, "打印时间：" + date.getFullYear() + "年" + (date.getMonth() + 1) + "月" + date.getDate() + "日");
        LODOP.SET_PRINT_STYLEA(i.toString() + fontsize, "FontSize", 12);
        LODOP.SET_PRINT_STYLEA(i.toString() + fontsize, "Bold", 1);
       
        var strStyle = "<style> table,td,th {border-width: 1px;border-style: solid;border-collapse: collapse;font-size:12px;}</style>"
        var str = '<table border="1" cellspacing="0" cellpadding="1" width="100%" style="border-collapse: collapse" bordercolor="#333333"><thead><tr><td width="10%"><div align="center"><b>序号</b></div></td><td width="15%"><div align="center"><b>货物编码</b></div></td><td width="50%"><div align="center"><b>货物描述</b></div></td><td width="12.5%"><div align="center"><b>调出数量</b></div></td><td width="12.5%"><div align="center"><b>调入数量</b></div></td></tr></thead><tbody id="tbBody">';

        $.each(result, function (q, n) {
            str += "<tr><td align='center'>" + (q + 1) + "</td><td align='center'>" + n.code + "</td><td align='center'>" + n.detail + " </td><td align='center'>" + n.out_num + " </td><td align='center'>" + n.in_num + " </td></tr>";
        });

        str += '</tbody></table>';
        LODOP.ADD_PRINT_TABLE("18%", "5%", "90%", "85%", strStyle + str);
        LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
        

        LODOP.ADD_PRINT_TEXT(25, "8%", 135, 20, "第#页/共&页");
        LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
        LODOP.SET_PRINT_STYLEA(0, "Horient", 1);
        LODOP.PREVIEW();
    }
</script>